package com.weikuang.fareast.adapter;

import android.annotation.TargetApi;
import android.os.Build;
import android.view.View;
import android.widget.LinearLayout;

import com.weikuang.fareast.R;
import com.weikuang.fareast.bean.BranchCodeList;
import com.weikuang.fareast.bean.HotelBean;

import cn.dlc.commonlibrary.ui.adapter.BaseRecyclerAdapter;

/**
 * 用于单击
 */
public class NumberAdapter extends BaseRecyclerAdapter<BranchCodeList.DataBean> {
    private int layoutPosition = -1;
    private OnRecyclerViewItemClickListener mOnItemClickListener;
    @Override
    public int getItemLayoutId(int viewType) {
        return R.layout.item_hotel;
    }


    @TargetApi(Build.VERSION_CODES.JELLY_BEAN)
    @Override
    public void onBindViewHolder(final CommonHolder holder, int position) {

        holder.getText(R.id.name).setText(getItem(position).getBranchCode());
        LinearLayout linearLayout = holder.getView(R.id.linear);
        linearLayout.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                //获取当前点击的位置
                layoutPosition = holder.getLayoutPosition();
                notifyDataSetChanged();
                if (mOnItemClickListener != null) {
                    mOnItemClickListener.onItemClick(holder.itemView, getItem(position), layoutPosition);
                }
            }
        });
        //更改状态
        if(position == layoutPosition){
            linearLayout.setBackgroundResource(R.drawable.yellow_text_pressed);
        }else{
            linearLayout.setBackgroundResource(R.drawable.yellow_text_normal);
        }

    }
    public void setInit(){
        layoutPosition = -1;
        notifyDataSetChanged();
    }
    public  interface OnRecyclerViewItemClickListener {
        void onItemClick(View view, BranchCodeList.DataBean data, int position);
    }

    public void setOnItemClickListener(OnRecyclerViewItemClickListener listener) {
        this.mOnItemClickListener = listener;
    }
}
